﻿namespace Leetcode.N1114.V2;

using System.Threading;

public class Foo
{
    private readonly ManualResetEvent resetEvent2 = new ManualResetEvent(false);
    private readonly ManualResetEvent resetEvent3 = new ManualResetEvent(false);

    public void First(Action printFirst)
    {
        printFirst();
        this.resetEvent2.Set();
    }

    public void Second(Action printSecond)
    {
        this.resetEvent2.WaitOne();
        printSecond();
        this.resetEvent3.Set();
    }

    public void Third(Action printThird)
    {
        this.resetEvent3.WaitOne();
        printThird();
    }
}